package com.tfw.domain;



import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @program: fruit-sale
 * @description: 折扣
 * @author: Fuwen
 * @create: 2022-07-27 18:21
 **/
public class Discount extends Preferential{
    /**
     * 打折力度
     */
    private BigDecimal disPrice;
    /**
     * 使用优惠
     * @param goods
     * @return
     */
    @Override
    public BigDecimal useCou(List<Good> goods) {
        //打折列表
        List<Good> couList = new ArrayList<>();
        boolean b=Objects.isNull(this.getBeginDate())&&Objects.isNull(this.getEndDate());
        for (Good good:goods){
            if (!b&&this.getGoodId().contains(good.getUuid())&&this.getBeginDate().compareTo(new Date())<0
                    &&this.getEndDate().compareTo(new Date())>0){
                if (!Objects.isNull(disPrice)&&disPrice.compareTo(BigDecimal.ZERO)>0){
                    couList.add(good);
                }
            }
        }
        for (Good good:couList){
            goods.remove(good);
        }
        BigDecimal decimal = BigDecimal.ZERO;
        if (goods.size()!=0){
            decimal=decimal.add(basePrice(goods));
        }
        BigDecimal decimal1 = BigDecimal.ZERO;
        if (couList.size()!=0){
            decimal1=decimal1.add(basePrice(couList));
            decimal1= decimal1.multiply(disPrice);
        }
        goods.addAll(couList);
        return decimal.add(decimal1);
    }

    public BigDecimal getDisPrice() {
        return disPrice;
    }

    public void setDisPrice(BigDecimal disPrice) {
        this.disPrice = disPrice;
    }
}
